import util from '@/network/common/util.js';
import $ from 'jquery'

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function (data) {
        return $.param(data)
    }
}
let api = {
    'getStorageList'        : '/storage/v1/getStorageList', //用户寄存列表
    'getStorage'            : '/storage/v1/getStorage', //根据订单id查询客存情况
    'getStorHouse'          : '/storage/v1/getStorHouse', //根据影院id查询影院仓库列表
    'addStorage'            : '/storage/v1/addStorage', //存入客存
    'upStorage'             : '/storage/v1/upStorage', //取出客存
    'getDepositDetails'     : '/storage/v1/getDepositDetails', //详情
    'getProduct'            : '/storage/v1/getProduct', //通过条形码获取商品信息
    
}
let res = {};
function getStorageList (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getStorageList, {
            page: params.page,
            pageSize: params.pageSize,
            selectName: params.selectName
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getStorage (did) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getStorage, {
            did: did,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getStorHouse (theatreId) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getStorHouse, {
            theatreId: theatreId
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function addStorage (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.addStorage, {
            userName: params.userName,
            phone: params.phone,
            storeHouseId: params.storeHouseId,
            accountId: params.accountId,
            remark: params.remark,
            pros: JSON.stringify(params.pros),
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function upStorage (did) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.upStorage, {
            did: did
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getDepositDetails (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getDepositDetails, {
            did: params.did,
            paging: params.paging,
            page: params.page,
            pageSize: params.pageSize,
            key: params.key,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getProduct (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getProduct, {
            name: params.name,
            productBar: params.productBar,
            fromStock: params.fromStock,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}


export default {
    getStorageList,
    getStorage,
    getStorHouse,
    addStorage,
    upStorage,
    getDepositDetails,
    getProduct

}